package cn.itsource.service.impl;

import cn.itsource.domain.ArticleType;
import cn.itsource.mapper.ArticleTypeMapper;
import cn.itsource.query.ArticleTypeQuery;
import cn.itsource.service.ArticleTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * 业务实现类：文章类型ArticleType
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class ArticleTypeServiceImpl implements ArticleTypeService {

    @Autowired
    private ArticleTypeMapper articleTypeMapper;

    @Override
    public List<ArticleType> findAll() {
        return articleTypeMapper.findAll();
    }

    @Override
    public ArticleType findOne(Long id) {
        return articleTypeMapper.findOne(id);
    }

    @Transactional
    @Override
    public void add(ArticleType articletype) { //
        articleTypeMapper.add(articletype);
    }

    @Transactional
    @Override
    public void update(ArticleType articleType) {
        articleTypeMapper.update(articleType);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        articleTypeMapper.delete(id);
    }

    @Override
    public PageInfo<ArticleType> pageQuery(ArticleTypeQuery query) {
       /* //查询总条数 - 原生分页的写法
        Integer totals = articleTypeMapper.queryCount();
        //查询当前页的分页数据
        List<ArticleType> list = articleTypeMapper.queryData(query);*/
        //开启分页：1.首先查询总数量 2.根据驱动名使用相应的方式进行分页查询，如果是mysql，就会用limit 3.自动计算limit的第1个参数
        PageHelper.startPage(query.getCurrentPage(),query.getPageSize());
        List<ArticleType> list = articleTypeMapper.pageQuery(query);
        return new PageInfo<>(list);
    }

    @Override
    public void patchDel(Long[] ids) {
        articleTypeMapper.patchDel(ids);
    }

}
